﻿using BepInEx;
using BepInEx.Configuration;
using System.Collections.Generic;
using WzhAddon;

namespace WzhStudioVMDPlay
{
    [BepInPlugin("WzhMode.WzhStudioVMDPlay", "WzhStudioVMDPlay", "1.0.0")]
    public class StudioVMDPlayManager : BaseUnityPlugin
    {
        public static StudioVMDPlayManager I { get; private set; }
        
        //ConfigEntry<string> myName;
        void Start()
        {
            if (Singleton<Studio.Studio>.Instance == null) return;
            ConfigEntry<string> myName= Config.Bind<string>("config", "myName", "myNamemyNamemyName", "测试字段");
            I = this;
            var path = Config.Bind<string>("config", "VmdPath", "", "Vmd文件夹路径");
            if (string.IsNullOrEmpty(path.Value)) { LogInfo(2, "  加载 失败  path 不存在"); return; }
          
            WLog.Manager = this;

            BaseMgr<MMD_VmdCameraLoad>.Install(base.gameObject);
            var VMDMgr = BaseMgr<HSVMDAnimationMgr>.Install(base.gameObject);
            BaseMgr<WzhAddon.DHHPlugIn.HighHeelRunTime>.Install(base.gameObject);

            var PlayGUI = BaseMgr<StudioVMDPlayGUI>.Install(base.gameObject);
            //string pathStr = path.Value.Replace(@"\", @"\\");
            string pathStr = path.Value;
            PlayGUI.InItGUI(pathStr);
            PlayGUI.AddVmdCallBack = VMDMgr.AddController;
            PlayGUI.LoadVMDCallBack = VMDMgr.LoadVMDAnimation;
            PlayGUI.PlayCallBack = VMDMgr.PlayAll;
            PlayGUI.PauseCallBack = VMDMgr.PauseAll;

            LogInfo(0, "加载 完成！！！！" + "path: " + path.Value);
        }

        private void Update()
        {
            if (I != null) return;
            Start();
        }

        public void LogInfo(int type, string info)
        {
            switch (type)
            {
                case 0: Logger.LogInfo(info); return;
                case 1: Logger.LogWarning(info); return;
                case 2: Logger.LogError(info); return;
            }
            Logger.LogInfo(info);
        }

    }
}
